package cn.us.eagle.query;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.mybatis.spring.support.SqlSessionDaoSupport;

import cn.us.eagle.query.criteria.QueryCriteria;

/**
 * @author ReasonZhong
 * 
 */
public class QueryImpl extends SqlSessionDaoSupport implements Query {

	protected final Log log = LogFactory.getLog(QueryImpl.class);

	@SuppressWarnings("rawtypes")
	public List queryForList(String statementName, QueryCriteria criteria) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("criteria", criteria);
		return this.getSqlSession().selectList(statementName, map);
	}

	public int queryForCount(String statementName, QueryCriteria criteria) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("criteria", criteria);
		Integer count = (Integer) getSqlSession().selectOne(statementName, map);
		return count.intValue();
	}

	@SuppressWarnings("rawtypes")
	public List queryForList(String statementName) {
		return this.getSqlSession().selectList(statementName);
	}

	public boolean isExists(String statementName, String value) {
		return (Integer) getSqlSession().selectOne(statementName, value) > 0;
	}
}
